import 'package:flutter/material.dart';
import 'package:pabu/widget/component/basic/basic_page.dart';
import 'package:pabu/widget/component/material/material_page.dart';

class ComponentPage extends StatefulWidget {
  @override
  _ComponentPageState createState() => new _ComponentPageState();
}

class _ComponentPageState extends State<ComponentPage> {
  @override
  Widget build(BuildContext context) {
    return _buildTabBar();
  }

  int _selectIndex = 0;

  Widget _buildTabBar() {
    return MaterialApp(
      home: DefaultTabController(
        length: _componentTypes.length,
        child: Scaffold(
          appBar: AppBar(
            title: Text("Component"),
            bottom: TabBar(
              isScrollable: true,
              tabs: _componentTypes.map((ComponentType componentType) {
                return new Tab(
                  text: componentType.name,
                );
              }).toList(),
              onTap: (index){
                this._selectIndex = 0;
              },
            ),
          ),
          body: TabBarView(
            children: _componentTypes.map((ComponentType componentType) {
              return componentType.page;
            }).toList(),
          ),
        ),
      ),
    );
  }
}

class ComponentType {
  ComponentType({this.ukId, this.name, this.page});

  String ukId;
  String name;
  Widget page;
}

List<ComponentType> _componentTypes = <ComponentType>[
  ComponentType(ukId: "1", name: "Basic", page: new BasicPage()),
  ComponentType(ukId: "2", name: "Material", page: new MaterialPage()),
  ComponentType(ukId: "5", name: "Cupertino", page: new BasicPage()),
  ComponentType(ukId: "3", name: "Layout", page: new BasicPage()),
  ComponentType(ukId: "4", name: "交互", page: new BasicPage()),
  ComponentType(ukId: "6", name: "滚动", page: new BasicPage()),
];